package com.dqx.haoqiu.repository.db;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.dqx.haoqiu.repository.entity.NewsEntity;

/**
 * 数据库持有者&&数据库版本管理者
 */
@Database(entities = {NewsEntity.class}, version = 1, exportSchema = false)
public abstract class DataBase extends RoomDatabase {
    private static final String DB_NAME = "news.db";
    public static DataBase dataBase;

    public static DataBase getInstance(Context context) {
        if (dataBase == null) {
            synchronized (DataBase.class) {
                if (dataBase == null) {
                    dataBase = Room.databaseBuilder(context, DataBase.class, DB_NAME)
                            .build();
                }
            }
        }
        return dataBase;
    }

    public abstract NewsDao getNewsDao();
}
